<%--
  Created by IntelliJ IDEA.
  User: ThinkPad
  Date: 2021/12/22
  Time: 2:23
  To change this template use File | Settings | File Templates.
--%>
<%-- 请勿直接访问此页面 --%>
<%@ page contentType="text/html;charset=UTF-8" import="dao.UserDao,domain.User"%>
<html>
<head>
    <title>注册信息反馈页面</title>
</head>
<body>
<%
    String username = request.getParameter("username");
    String password1 = request.getParameter("password1");
    String password2 = request.getParameter("password2");
    UserDao dao = new UserDao();
    boolean legal = true;
    // 输入的检测是不完全的，还需要对用户输入数据的合法性进行进一步检测
    if (dao.exist(username)){
        legal = false;
%>
<script type="text/javascript">
    alert("很遗憾，您填写的用户名已被抢注:(");
    window.location="register.jsp";
</script>
<%
    }
    if (!password1.equals(password2)){
        legal = false;
%>
<script type="text/javascript">
    alert("您两次输入的密码不一致！");
    window.location="register.jsp";
</script>
<%
    }
    if (legal) {
        // 合法性检测通过，接下来尝试在数据库中加入新用户
        User user = new User();
        user.setUsername(username);
        user.setPassword(password1);
    if (dao.insert(user)){
%>
<div style="font-size: larger;color: chocolate;text-align: center;">恭喜您，注册成功！</div><br />
<div style="text-align: center">
请牢记您的注册信息：
<table style="margin-left: 35%">
    <tr>
        <td>用户名：</td>
        <td><%=request.getParameter("username")%></td>
    </tr>
    <tr>
        <td>密 码：</td>
        <td><%=request.getParameter("password1")%></td>
    </tr>
</table>
<a href="login.jsp">立即登录！</a>
<%
        }
    }
%>
</div>
<br /><br /><br /><br /><br /><br />
<%@include file="tail.jsp"%>
</body>
</html>
